# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=wcag-contrast-ratio
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.9
pkgrel=2
pkgdesc="Library for computing contrast ratios, as required by WCAG 2.0 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/gsnedders/wcag-contrast-ratio'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-hypothesis")
source=("${_realname}-${pkgver}.tar.gz"::"$url/archive/$pkgver/${_realname}-${pkgver}.tar.gz")
sha256sums=('5263b7b2d0f5a8de2eb409421284947df6229b67bca0055fa10da38153835815')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  ## (OPTIONAL) Only if setuptools-scm is used
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/pytest test.py
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    "${MINGW_PREFIX}"/bin/python setup.py install --prefix="${MINGW_PREFIX}" \
      --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
